home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Sep 89 / Y0023-StuffText Bug-Sep89 < prev    next >
Encoding:
Text File  |  1989-09-07  |  5.4 KB  |  152 lines  |  [TEXT/GEOL]

  1. Item    3690442                         7-Sept-89        05:35
  2.  
  3. From:   D2769                           Comusearch, James Benson,PRT
  4.  
  5. To:     MACAPP.TECH$                    MACAPP Tech
  6.  
  7. cc:     MACAPP.TEST                     MacApp SQA Team,APL
  8.  
  9. Sub:    StuffText Bug
  10.  
  11.  
  12. A while back I sent a message to MacDTS about a bug in StuffText.  I thought
  13. the fix would make it in MacApp 2.0b9,  but it didn't.  So,  here is a copy of
  14. my message, and the MacDTS reply to it.
  15.  
  16. I am sending this to Macapp.Tech$ so that everybody else is able to see this
  17. and make the appropriate corrections to their code.
  18.  
  19. Have fun everybody.
  20.  
  21. Manuel Perez
  22.  
  23. ============================  MY MESSAGE ============================
  24.  
  25. MacDTS,
  26.  
  27. I finally tracked down the problem with TEView and setting styles.  I had sent
  28. a link a few weeks back,  but seems like my description was not enough for you
  29. to help me out (no surprise there, since I did not know what was happening
  30. either).
  31.  
  32. Background: I have an application that searches a text database for some
  33. keywords, and brings to a window sections of text (that contain the keywords).
  34. The text cannot be modified.  It is shown using a TEView with the keywords in
  35. bold.  If the user searches again, I StuffText the new section of text into the
  36. TEView.  Setting styles the second time seemed to hang up the Mac.  After a
  37. little playing around, I found out a way to fix it (and what I think is a bug).
  38.  
  39. The Problem:  I have repeated the problem using the DemoText application
  40. included in MacApp 2.0b5.  Add the following two procedures inside the
  41. DoMenuCommand of the DemoText document.  Also, add two menu items that will
  42. call each one of this procedures.
  43.  
  44. ----------------------------------------------------------
  45.     PROCEDURE StuffFirstText;
  46.      VAR
  47.            theStyle: TextStyle;
  48.      BEGIN
  49.            theStyle := fTEView.fTextStyle;      { Get current text style }
  50.            theStyle.tsFace := [bold];           { set face to bold }
  51.            fTEView.SetText('This text will have the word bold in bold.');
  52.            fTEView.SetOneStyle(37, 42, doFace, theStyle, kDontRedraw);  { set style }
  53.         { of the last word 'bold' to bold }
  54.            SetSelect(0, 0, fTEView.fHTE);       { Set insertion point at beginning }
  55.            fTEView.RecalcText;                  { Recalc text }
  56.            fTEView.ForceRedraw;                 { and redraw the TEView }
  57.      END;
  58.     
  59.     PROCEDURE StuffSecondText;
  60.      VAR
  61.            theStyle: TextStyle;
  62.      BEGIN
  63.            theStyle := fTEView.fTextStyle;          { see comments above }
  64.            theStyle.tsFace := [bold];
  65.            fTEView.SetText('This is some text that will be inserted and later some
  66. words will be made bold');
  67.            fTEView.SetOneStyle(50, 55, doFace, theStyle, kDontRedraw);
  68.            SetSelect(0, 0, fTEView.fHTE);
  69.            fTEView.RecalcText;
  70.            fTEView.ForceRedraw;
  71.      END;
  72. ------------------------------------
  73.  
  74. Now, compile and run the DemoText sample program.  Execute the StuffFirstText
  75. followed by the StuffSecondText procedures.  In my machine (both home II and
  76. work IIx), the procedure executed second will hang the Mac.
  77.  
  78. Solution:  If the SetOneStyle method calls were commented out, the application
  79. would work without any problems, so I figure the problem was with SetOneStyle.
  80. WRONG.  The problem is caused by StuffText, but it occurs when SetOneStyle is
  81. called again.  I have added two lines to the StuffText method that fixed the
  82. problem.  The explanation to them seem very clear, but are basically
  83. speculations.  What happens is, that StuffText tries to get rid of the style
  84. information by setting the runs[1].startChar equals to the size of the TEHandle
  85. + 1 (as specified by IM-V).  But, it does NOT modify the nRuns or nStyles
  86. count.  It seems like TextEdit uses those counter some place and it tries to
  87. access past the end of a handle (namely the styles and runs tables).  So, I
  88. reset the nRuns and nStyles to 1 and, like magic, everything works fine.
  89.  
  90.  
  91. ------------------------------
  92. In TTEView.StuffText…
  93.  
  94.            IF fStyleType = kWithStyle THEN            { Fix for styled TE.  Yuk.                    }
  95.                 BEGIN
  96.                  styles := GetStylHandle(fHTE);
  97.                  styles^^.runs[1].startChar := SUCC(fHTE^^.teLength);
  98.  
  99.                  { added the next two lines or else the application will hang }
  100.                  styles^^.nRuns := 1;       { maybe only one is sufficient but }
  101.                  styles^^.nStyles := 1;     { what the heck, better safe than sorry }
  102.                  { that’s it.  map 5/23/89 }
  103.  
  104.                 END;
  105.  
  106. ----------------------------
  107.  
  108. Question: Is this correct?  Was that a bug, or should I have called another
  109. method (that I am unaware of) in my StuffxxxxText procedures?
  110.  
  111. I am using MacApp 2.0b5, but I looked at 2.0b8 and the code for the relevant
  112. section is still the same, so I suspect that this will still happen.
  113.  
  114.  
  115. As always, thanks for your attention and support.
  116.  
  117.  
  118. Manuel A. Perez
  119. Software Engineer
  120. Compusearch Software Systems
  121. AppleLink:  D2769
  122. (703) 893-7200
  123.  
  124. ============================  MACDTS REPLY ============================
  125.  
  126. Item    6812530                         30-May-89        19:28
  127.  
  128. From:   SHEBANOW1                       Shebanow, Andrew
  129.  
  130. To:     D2769                           Comusearch, James Benson, PRT
  131.  
  132. Sub:    TEView bug
  133.  
  134. To: D2769 (Manuel Perez, Compusearch)
  135. Subject: TEView bug
  136. ----------------------------------------------------------------------
  137. Hello,
  138.  
  139. I have confirmed the bug, and passed it on to the MacApp
  140. engineers. Thanks for your great detective work.
  141.  
  142. Have fun,
  143.  
  144. Andrew Shebanow
  145. MacDTS
  146. Apple Computer, Inc.
  147.  
  148. (L5/25/89.31)
  149.  
  150.  
  151.  
  152.